/*
package net.fkzg.framework.task;

import com.alibaba.fastjson.JSONObject;
import com.github.jarvett.http.SmartHttpApplication;
import com.github.jarvett.utils.HttpUtil;
import com.mysql.cj.jdbc.MysqlDataSource;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.MapListHandler;

import javax.sql.DataSource;
import java.text.MessageFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

@Slf4j
class TaskBizJob {

    private static DateTimeFormatter DTF = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    TaskBizJob() {
        DbUtils.loadDriver(SmartHttpApplication.getPropValue("jdbc.driverClassName"));
    }

    private DataSource getDataSource() {
        MysqlDataSource ds = new MysqlDataSource();
        ds.setUrl(SmartHttpApplication.getPropValue("jdbc.jdbcUrl"));
        ds.setUser(SmartHttpApplication.getPropValue("jdbc.username"));
        ds.setPassword(SmartHttpApplication.getPropValue("jdbc.password"));
        return ds;
    }

    @SneakyThrows
    void monitorReward() {
        //监控金蝉打赏
        QueryRunner queryRunner = new QueryRunner(getDataSource());
        try {
            int m  = Integer.parseInt(SmartHttpApplication.getPropValue("job.lastMin"));
            int t = Integer.parseInt(SmartHttpApplication.getPropValue("job.threshold"));
            String from = LocalDateTime.now().minusMinutes(m).format(DTF);
            String sql = "SELECT u.phone,u.nick_name,t.num FROM (SELECT ti.to_user_id,count(0) AS num FROM (SELECT to_user_id,user_id FROM `uv_user_reward_record` WHERE video_type=2 AND reap_sys_jc_number > 0 AND create_time > ? ) ti LEFT JOIN us_user ui ON ui.id = ti.user_id WHERE ui.isrobot=0 GROUP BY ti.to_user_id ) t LEFT JOIN `us_user` u ON t.to_user_id = u.id ORDER BY t.num DESC";
            List<Map<String,Object>> resultList = queryRunner.query(sql, new MapListHandler(),from);
            StringBuilder ctb = new StringBuilder();
            resultList.forEach(j -> {
                JSONObject item = new JSONObject(j);
                int num = item.getIntValue("num");
                if(num > t){
                    ctb.append(String.format("手机号:%s    ",item.getString("phone")))
                            .append(String.format("数量:%-8s",item.getString("num")))
                            .append(String.format("昵称:%s\n",item.getString("nick_name")))
                            ;
                }
            });
            if(ctb.length() > 0){
                log.info(ctb.toString());
                this.sendMsgToDingTalk(MessageFormat.format("最近{0}分钟检测到以下用户收到非机器人打赏数据",m),ctb.toString());
            }
            log.debug("本次任务执行完成！！！r={}",Math.random());
        } catch (Exception e) {
            log.warn("monitor run error ", e);
        }finally {
            DbUtils.closeQuietly(queryRunner.getDataSource().getConnection());
        }
    }

    public void sendMsgToDingTalk(String title,String content) {
        JSONObject json = new JSONObject();
        json.put("msgtype","text");
        JSONObject text = new JSONObject();
        text.put("content","INFO:"+LocalDateTime.now().format(DTF)+"\n" + title + "\n"+ content);
        json.put("text",text);
        //正式群
         HttpUtil.sendPostJson("https://oapi.dingtalk.com/robot/send?access_token=0d71a23d52b09a660156ef88d0d6f754b5e65353e36a9de52e9e6fca2690203c",json.toJSONString());
        //调试群
//        HttpUtil.sendPostJson("https://oapi.dingtalk.com/robot/send?access_token=b44741d02c17bd56a029a1f50854605b6806454ea8cb4aa3099bd844087e5fd3",json.toJSONString());
    }

}
*/
